package cn.ehanghai.htz.controller;

import cn.ehanghai.htz.client.TcpClient;
import cn.ehanghai.htz.common.constants.ReturnCode;
import cn.ehanghai.htz.domain.Position;
import cn.ehanghai.htz.service.PositionService;
import cn.ehanghai.htz.vo.ShipVo;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: xumf
 * @Date: 2019/6/21 14:04
 */
@RequestMapping("/ship")
@RestController
@CrossOrigin
public class IndexController {

    @Autowired
    private PositionService positionService;

    /**
     * 获取虚拟的船舶信息
     */
    @GetMapping("/getVirtual")
    public ReturnCode getVirtualShip(@RequestParam(name = "IsShow",defaultValue = "1") Integer IsShow){
        if(StringUtils.isEmpty(TcpClient.getSocket())){
           return new ReturnCode(100,"未连接上服务");
        }
        List<ShipVo> list=new ArrayList<>();
        if(IsShow==1){
            list=positionService.selectList();
            return ReturnCode.success(list);
        }
        else{
            return ReturnCode.success(list);
        }

    }

    @GetMapping("/list")
    public ReturnCode test(@RequestParam(name = "IsShow",defaultValue = "1")Integer IsShow){
        List<ShipVo> list=new ArrayList<>();
        if(IsShow==1){
            list=positionService.selectList();
            return ReturnCode.success(list);
        }
        else{
            return ReturnCode.success(list);
        }

//        JSONObject result = new JSONObject();
//        result.put("result",list);
//        result.put("isVirtual",true);

    }


}

